home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 8.2 KB | 288 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWFontLi.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWFONTLI_H
- #include "FWFontLi.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- #ifndef FWSTRING_H
- #include "FWString.h"
- #endif
-
- #ifndef _ITEXT_
- #include "IText.h"
- #endif
-
- // ----- Platform Includes -----
-
- #ifdef FW_BUILD_WIN
- #include <windows.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__MENUS__)
- #include <Menus.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__SCRIPT__)
- #include <Script.h>
- #endif
-
- //========================================================================================
- // Runtime infos
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphx_FontList
- #endif
-
- //========================================================================================
- // Template Instantiations
- //========================================================================================
-
- FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_CString)
- FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, FW_CString)
-
- #ifdef FW_USE_TEMPLATE_PRAGMAS
-
- #pragma template_access public
- #pragma template FW_TOrderedCollection<FW_CString>
- #pragma template FW_TOrderedCollectionIterator<FW_CString>
-
- #endif
-
- //========================================================================================
- // CLASS FW_CFontList
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CFontList)
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // PrivWinFillFontList
- //
- // Windows callback method to insert font names into the supplied list.
- //----------------------------------------------------------------------------------------
-
- static int CALLBACK PrivWinFillFontList(const LOGFONT* lplf,
- const TEXTMETRIC* /* lptm */,
- DWORD /* dwFontType */,
- LPARAM lParam)
- {
- FW_TOrderedCollection<FW_CString>* list = (FW_TOrderedCollection<FW_CString>*) lParam;
- FW_CString* fontName = new FW_CString((FW_Char*) lplf->lfFaceName);
- list->AddLast(fontName);
- return TRUE; // Keep going
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CFontList::FW_CFontList
- //----------------------------------------------------------------------------------------
-
- FW_CFontList::FW_CFontList()
- {
- #ifdef FW_BUILD_MAC
- const short dummyMenuID = 7777;
- MenuHandle fontListHolder = ::NewMenu(dummyMenuID, "\pODF");
-
- if (fontListHolder == NULL)
- FW_Failure(FW_xMemoryExhausted);
-
- short count = 0;
-
- FW_TRY
- {
- ::AppendResMenu(fontListHolder, 'FONT');
- count = ::CountMItems(fontListHolder);
- Str255 itemName;
-
- // get System script code and language code
- long systemScriptCode = ::GetScriptManagerVariable(smSysScript);
- long systemLanguageCode = ::GetScriptVariable(systemScriptCode, smScriptLang);
- short itemField;
-
- for (short k = 1; k <= count; k++)
- {
- ::GetMenuItemText(fontListHolder, k, itemName);
- ::GetItemCmd(fontListHolder, k, &itemField); // Check cmd key equivalent code
-
- ODScriptCode scriptCode = (ODScriptCode) systemScriptCode;
- ODLangCode languageCode = (ODLangCode) systemLanguageCode;
-
- if (itemField == 0x1C)
- // key equiv value of 0x1C indicates that the icon field contains a script code
- {
- ::GetItemIcon(fontListHolder, k, &itemField); // get script code from icon field
- scriptCode = (ODScriptCode) itemField;
- if (itemField == 0x00FF) /* kludge */
- scriptCode = (ODScriptCode) systemScriptCode;
- // Get the language code from the script code
- languageCode = (ODLangCode) ::GetScriptVariable(scriptCode, smScriptLang);
- }
-
- FW_CString* fontName = FW_NEW(FW_CString, ());
- ODIText* text = CreateIText(scriptCode, languageCode, itemName);
- fontName->ReplaceAll(text);
- DisposeIText(text);
- fCollection.AddLast(fontName);
- }
- ::DisposeMenu(fontListHolder);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- ::DisposeMenu(fontListHolder);
- FW_THROW_SAME();
- }
- FW_CATCH_END
- #endif
-
- #ifdef FW_BUILD_WIN
- HDC dc = ::GetDC(NULL);
- if(dc != 0)
- {
- FW_TRY
- {
- ::EnumFontFamilies(dc, NULL, ::PrivWinFillFontList, (LPARAM)&fCollection);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- ::ReleaseDC(NULL, dc);
- FW_THROW_SAME();
- }
- FW_CATCH_END
- ::ReleaseDC(NULL, dc);
- }
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFontList::~FW_CFontList
- //----------------------------------------------------------------------------------------
-
- FW_CFontList::~FW_CFontList()
- {
- FW_TOrderedCollectionIterator<FW_CString> ite(&fCollection);
- for (FW_CString* fontName = ite.First(); ite.IsNotComplete(); fontName = ite.Next())
- {
- delete fontName;
- }
- }
-
- //========================================================================================
- // CLASS FW_CFontIterator
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CFontIterator)
-
- //----------------------------------------------------------------------------------------
- // FW_CFontIterator::FW_CFontIterator
- //----------------------------------------------------------------------------------------
-
- FW_CFontIterator::FW_CFontIterator() :
- fFontList(NULL),
- fDeleteTheList(TRUE),
- fIterator(NULL)
- {
- fFontList = FW_NEW(FW_CFontList, ());
- fIterator = FW_NEW(FW_TOrderedCollectionIterator<FW_CString>, (&fFontList->fCollection));
-
- FW_END_CONSTRUCTOR
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CFontIterator::FW_CFontIterator
- //----------------------------------------------------------------------------------------
-
- FW_CFontIterator::FW_CFontIterator(FW_CFontList* fontList) :
- fFontList(fontList),
- fDeleteTheList(FALSE),
- fIterator(NULL)
- {
- FW_ASSERT(fontList != NULL);
-
- fIterator = FW_NEW(FW_TOrderedCollectionIterator<FW_CString>, (&fFontList->fCollection));
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFontIterator::~FW_CFontIterator
- //----------------------------------------------------------------------------------------
-
- FW_CFontIterator::~FW_CFontIterator()
- {
- FW_START_DESTRUCTOR
-
- if (fDeleteTheList)
- delete fFontList;
-
- delete fIterator;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFontIterator::First
- //----------------------------------------------------------------------------------------
-
- FW_CString FW_CFontIterator::First()
- {
- FW_CString *name = fIterator->First();
- return name ? *name : FW_CString("");
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFontIterator::Next
- //----------------------------------------------------------------------------------------
-
- FW_CString FW_CFontIterator::Next()
- {
- FW_CString *name = fIterator->Next();
- return name ? *name : FW_CString("");
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFontIterator::Last
- //----------------------------------------------------------------------------------------
-
- FW_CString FW_CFontIterator::Last()
- {
- FW_CString *name = fIterator->Last();
- return name ? *name : FW_CString("");
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFontIterator::Previous
- //----------------------------------------------------------------------------------------
-
- FW_CString FW_CFontIterator::Previous()
- {
- FW_CString *name = fIterator->Previous();
- return name ? *name : FW_CString("");
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFontIterator::IsNotComplete
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CFontIterator::IsNotComplete()
- {
- return fIterator->IsNotComplete();
- }
-
-